package com.wtgroup.demo.mianshi.设计模式.单例;

/**
 * @author dafei
 * @version 0.1
 * @date 2020/6/12 10:07
 */
public class 饿汉 {
    public static void main(String[] args) {
        SingletonEh inst1 = SingletonEh.getInstance();
        SingletonEh inst2 = SingletonEh.getInstance();
        System.out.println("inst1 == inst2 ? " + (inst1 == inst2));
    }
}


class SingletonEh {
    // 类加载时初始化实例    线程安全
    public static final SingletonEh INSTANCE = new SingletonEh();

    // 私有构造
    private SingletonEh(){}

    public static SingletonEh getInstance() {
        return INSTANCE;
    }

}
